package org.study.enums;

/**
 * 枚举类可以实现命令模式，每个枚举常量代表一个具体的命令。
 * 参考 https://blog.csdn.net/MeyrlNotFound/article/details/147870300
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年07月16日
 */
public class CommandEnumTest2 {
    public static void main(String[] args) {
        TextEditor textEditor = new TextEditor();
        TextEditorCommand copy = TextEditorCommand.COPY;
        copy.execute(textEditor);
    }

    public enum TextEditorCommand {
        COPY {
            @Override
            public void execute(TextEditor editor) {
                editor.copy();
            }
        },
        PASTE {
            @Override
            public void execute(TextEditor editor) {
                editor.paste();
            }
        },
        CUT {
            @Override
            public void execute(TextEditor editor) {
                editor.cut();
            }
        },
        UNDO {
            @Override
            public void execute(TextEditor editor) {
                editor.undo();
            }
        };

        public abstract void execute(TextEditor editor);
    }

    public static class TextEditor {
        public void copy() {
            System.out.println("复制文本");
        }

        public void paste() {
            System.out.println("粘贴文本");
        }

        public void cut() {
            System.out.println("剪切文本");
        }

        public void undo() {
            System.out.println("撤销操作");
        }
    }
}
